<template>
  <div class="app-container">
    <div class="zd3">
      <div class="zd3-title">
        <p>
          <span>领料人</span>
          <input v-model="search.operator" type="text" placeholder="请输入领料人" />
        </p>
        <p>
          <span>状态</span>
          <el-select v-model="search.statics" placeholder="请选择状态" class="userselect">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            ></el-option>
          </el-select>
        </p>
        <p>
          <span>单据日期</span>
          <input v-model="search.purchaseTime" type="text" placeholder="请输入单据日期" />
        </p>
        <h3 @click="getList">查询</h3>
        <h4 @click="resetList">重置</h4>
				<h3 @click="addPeople" style="background: #0093FF">新增</h3>
      </div>
      <div class="zd3-btm">
        <el-table :data="tableData" style="width: 100%;border-radius: 8px;" v-loading="loading">
          <el-table-column type="index" align="center" width="50" label="序号" />
          <el-table-column align="center" width="100" label="单据状态" >
            <template slot-scope="scope">
              <div class="orderStatus">
								<p v-if='scope.row.statics == 0' class="yellow">未提交</p>
								<p v-if='scope.row.statics == 1' class="blue">审批中</p>
								<p v-if='scope.row.statics == 2' class="blue">采购中</p>
								<p v-if='scope.row.statics == 3' class="green">入库</p>
								<p v-if='scope.row.statics == 10' class="green">已入库</p>
								<p v-if='scope.row.statics == 4' class="blue">出库</p>
								<p v-if='scope.row.statics == 9' class="green">已出库</p>
								<p v-if='scope.row.statics == 5' class="green">运行</p>
								<p v-if='scope.row.statics == 6' class="blue">维修</p>
								<p v-if='scope.row.statics == 7' class="red">报废</p>
								<p v-if='scope.row.statics == 8' class="red">驳回</p>
              </div>
            </template>
          </el-table-column>
          <!-- <el-table-column align="center" prop="outProtips" label="退货标志" fixed="left" /> -->
          <el-table-column align="center" prop="invoices" label="单据号" />
          <el-table-column align="center" prop="purchaseTime" width="100" label="单据日期" />
          <!-- <el-table-column align="center" prop="supplierId" width="150" label="往来单位名称" /> -->
          <el-table-column align="center" prop="departments" label="部门名称" />
          <el-table-column align="center" prop="operator" label="领料人" />
          <!-- <el-table-column align="center" prop="unitPrice" width="150" label="采购金额" /> -->
          <el-table-column align="center" prop="operator" width="100" label="制单人" />
          <el-table-column align="center" prop="insertTime" width="100" label="创建日期" />
          <el-table-column align="center" width="250" label="操作" fixed="right">
            <template slot-scope="scope">
              <el-button type="text" size="small" @click="look(scope.row)">查看</el-button>
              <el-button type="text" size="small" v-if="scope.row.statics == 0 || scope.row.statics == 8" @click="write(scope.row, scope.$index)">编辑</el-button>
							<el-button type="text" size="small" v-if="scope.row.statics == 0 || scope.row.statics == 8" @click="hanleSp(scope.row)">提交审批</el-button>
              <el-button type="text" size="small" v-if="scope.row.statics == 1 && userType == 2" @click="sureSp(scope.row)">审批</el-button>
              <el-popconfirm
                placement="top"
                hideIcon
                title="是否要删除此行？"
                @onConfirm="deleteRow(scope.row)"
              >
                <el-button type="text" size="small" slot="reference">删除</el-button>
              </el-popconfirm>
            </template>
          </el-table-column>
        </el-table>
        <el-pagination
          background
          hide-on-single-page
          layout="prev, pager, next"
          :total="total"
          :page-size="50"
          @current-change='goPage'
          @prev-click="goPrev"
          @next-click="goNext"
        />
      </div>
    </div>
		<el-dialog title="确认审批" :visible.sync="spBox" width="80%">
		  <div class="change">
		    <p>
					<span>操作</span>
		      <el-radio v-model="spItem.reults" label='true'>同意</el-radio>
		      <el-radio v-model="spItem.reults" label='false'>驳回</el-radio>
		    </p>
				<p>
					<span>备注</span>
				  <el-input type="text" v-model="spItem.flowRemarks" placeholder="请输入审批备注" class="userselect"></el-input>
				</p>
		  </div>
		  <span slot="footer" class="dialog-footer">
		    <el-button @click="spBox = false">取 消</el-button>
		    <el-button type="primary" @click="buzhangSp" :disabled="isClick">确 定</el-button>
		  </span>
		</el-dialog>
  </div>
</template>

<script>
// import { regionData } from 'element-china-area-data'
import { selectCaigou,selectProduct,deleteCaigou,updateCaigouHeader } from '@/api/caigou'
import { lingliaoShenhe } from '@/api/bumen'
export default {
  data() {
    return {
      search: {
        currentPage: 1
      },
      total: 1,
      showHeader: false,
			loading: true,
      selectedOptions: [],
      tableData: [],   //进货单
      dialogVisible: false,
      tempData: '',
      tempIndex: -1,
      options: [
        {
          label: '未提交',
          value: '0'
        },
        {
          label: '审批中',
          value: '1'
        },
        {
          label: '出库',
          value: '4'
        },
        {
          label: '已出库',
          value: '9'
        },
        {
          label: '驳回',
          value: '8'
        }
      ],
      value: '',
      djtime: '',
			userType: '',   //登录人身份
			spItem: '',    //部长审批数据
			spBox: false,
			isClick: false,   //是否点击
    }
  },
  mounted(){
    this.getList()
		const usertype = this.$store.state.user.userInfo[0]
		if(usertype.power == '员工'){
			this.userType = 1
		}else if(usertype.power == '部长'){
			this.userType = 2
		}else if(usertype.power == '总监'){
			this.userType = 3
		}else if(usertype.power == '总经理'){
			this.userType = 4
		}else{
			this.userType = 5
		}
  },
  methods: {
    // 获取领料单
    getList() {
			// let params = {
			// 	operator: this.username ? this.username : null
			// }
      selectCaigou(this.search).then(res => {
        console.log(res)
				const user = this.$store.state.user.userInfo[0]
        console.log(user)
        if(this.$store.state.user.userInfo[0].roleList[0].roleName != 'superAdmin'){
          const filterlist = res.data.list.filter(item => item.departments === user.departments && item.purchaseType == '领料')
          console.log(filterlist)
          this.tableData = filterlist
        }else{
          const filterlist = res.data.list.filter(item => item.purchaseType == '领料')
          console.log(filterlist)
          this.tableData = filterlist
        }
				
				this.loading = false
      })
    },
		// 员工提交审批
		hanleSp(item){
			console.log(item)
			updateCaigouHeader({
				purchaseId: item.purchaseId,
				statics: 1,
				status: 2
			}).then(res => {
			  console.log(res)
			  this.$message({
			    message: res.message,
			    type: 'success'
			  })
				this.getList()
			})
		},
		// 部长确认审批
		sureSp(item){
			this.spBox = true
			item.reults = JSON.stringify(item.reults)
			this.spItem = {...item}
			console.dir(this.spItem)
		},
		buzhangSp(){
			this.isClick = true
			console.dir(this.spItem)
			lingliaoShenhe({
				reults: JSON.parse(this.spItem.reults),
				purchaseId: this.spItem.purchaseId,
				puuids: this.spItem.puuids,
				status: this.spItem.status,
				transports: this.spItem.transports,
				flowRemarks: this.spItem.flowRemarks
			}).then(res => {
				this.isClick = false
				console.log(res)
				this.$message({
					message: res.message,
					type: 'success'
				})
				this.getList()
				this.spBox = false
			})
		},
		// 查看详情
    look(item){
      console.log(item)
      this.$router.push({
        name: "Writepickinglist",
        params: {
          look: 'look',
          options: JSON.stringify(item)
        }
      })
    },
		// 确认出库操作
    // sureIn(item){
    //   console.log(item)
    //   this.$router.push({
    //     name: "Sureoutstock",
    //     params: {
    //       options: JSON.stringify(item)
    //     }
    //   })
    // },
		// 编辑操作
    write(item, index) {
      console.log(item)
      this.$router.push({
        name: "Writepickinglist",
        params: {
          options: JSON.stringify(item)
        }
      })
    },
    save(item) {},
		// 删除操作
    deleteRow(item) {
      console.log(item)
      console.log("删除")
      deleteCaigou(item.purchaseId).then(res => {
        console.log(res)
        this.$message({
          message: res.message,
          type: 'success'
        })
        this.getList()
      })
    },
    goPage(page){
      this.search.currentPage = page
      this.getList()
    },
    goPrev(page) {
      this.search.currentPage--
      this.getList()
      console.log(page)
    },
    goNext(page) {
      this.search.currentPage++
      this.getList()
      console.log(page)
    },
    resetList() {
      this.search = {}
    },
		// 新增入库单
    addPeople(item) {
      this.$router.push({ name: "Writepickinglist" })
    }
  }
}
</script>

<style lang="scss" scoped>
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e !important;
  border-color: #18a05e !important;
}
/deep/.el-button--primary:hover,
.el-button--primary:focus {
  background: #18a05e !important;
  border-color: #18a05e !important;
  color: #fff !important;
}
/deep/.el-button:hover,
.el-button:focus {
  color: #18a05e;
  background-color: transparent;
}
/deep/.el-button--primary {
  color: #fff;
  background-color: #18a05e;
  border-color: #18a05e;
}
/deep/.el-button--text {
  color: #00c666 !important;
}
.app-container {
  padding: 10px;
}
.orderStatus {
  display: flex;
	justify-content: center;
  > p {
    padding: 0px 5px;
    color: #fff;
    border-radius: 2px;
    margin: 0 0px 0 0;
  }
  .blue {
    background: #3a87ad;
  }
  .green {
    background: #18a05e;
  }
  .yellow {
    background: #ff7a0e;
  }
  .red {
    background: #c60000;
  }
}

.status {
  border-radius: 3px;
  font-size: 14px;
  width: 50px;
  color: #fff;
  background: #777777;
  margin: 0 auto;
}
.status-active {
  background: #18a05e;
}
.inps {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  background: none;
  border: none;
  color: #333;
}
.inps-active {
  width: 100%;
  height: 32px;
  line-height: 32px;
  padding-left: 10px;
  // background:#ccc;
  border: none;
  color: #333;
}
.zd3-title {
	height: 80px;
	display: flex;
	align-items: center;
	padding: 0 20px;
	position: relative;
	background: #ffffff;
	border-radius: 8px;
	border: 1px solid rgba(0, 0, 0, 0.1);

	> p {
		font-size: 14px;
		color: #333;
		margin-right: 15px;

		> span {
			padding-right: 10px;
		}

		> input {
			width: 180px;
			height: 32px;
			// background: #ccc;
			border-radius: 3px;
			border: 1px solid #ccc;
			padding-left: 10px;
			color: #333;
		}
	}

	> h3 {
		width: 64px;
		height: 32px;
		background: #18a05e;
		border-radius: 3px;
		margin: 0 30px 0 0;
		color: #fff;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
	}

	> h4 {
		width: 64px;
		height: 32px;
		border-radius: 3px;
		border: 1px solid rgba(0, 0, 0, 0.1);
		color: #333;
		font-size: 14px;
		line-height: 32px;
		font-weight: 100;
		text-align: center;
		cursor: pointer;
		margin-right: 30px;
	}
}
.zd3-btm .btn-prev:after {
  content: "上一页";
}
.zd3-btm .btn-next:before {
  content: "下一页";
}
.zd3-btm .btn-prev,
.zd3-btm .btn-next {
  width: 65px;
}
.zd3-btm {
  background: rgba(255, 255, 255, 1);
  border-radius: 8px;
  border: 1px solid rgba(0, 0, 0, 0.1);
  margin-top: 10px;
  overflow: hidden;
	/deep/.el-button--text[data-v-318d347c] {
	  margin: 0 10px;
	}
  &-title {
    display: flex;
    align-items: center;
    height: 70px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.1);
    background: #ffffff;
    > p {
      text-align: center;
      font-size: 16px;
      color: #333;
    }
  }
  .el-pagination {
		white-space: nowrap;
		padding: 15px 5px;
		color: #303133;
		font-weight: bold;
	}
  .addDate {
    margin: 20px 32px 10px 32px;
    height: 32px;
    border-radius: 3px;
    text-align: center;
    line-height: 32px;
    font-size: 14px;
    color: #333;
    cursor: pointer;
    border: 1px dashed rgba(0, 0, 0, 0.25);
  }
  .el-button--text {
    margin: 0 15px;
  }
}
.change {
  display: flex;
  flex-wrap: wrap;
  > p {
    width: 50%;
    font-size: 14px;
    display: flex;
    align-items: center;
    color: #333;
    /deep/.el-input__inner {
      width: inherit;
      background: none;
      height: 32px;
      // line-height: 32px;
      color: #333;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding: 0 25px;
    }
    /deep/.el-input__icon {
      line-height: 32px;
    }
    .userselect {
      // max-width: 250px;
      flex: 1;
    }

    > span {
      display: block;
      width: 120px;
      text-align: right;
      padding-right: 15px;
    }
    > input {
      width: inherit;
      flex: 1;
      height: 32px;
      border-radius: 3px;
      border: 1px solid rgba(0, 0, 0, 0.1);
      padding-left: 10px;
      color: #333;
    }
  }
}
</style>
